<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>在 SELECT 中使用 PHP 变量作为定义的步骤</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.oci-define-by-name" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_define_by_name</h1>
  <p class="verinfo">(PHP 5, PHP 7, PECL OCI8 &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_define_by_name</span> &mdash; <span class="dc-title">在 SELECT 中使用 PHP 变量作为定义的步骤</span></p>

 </div>
 <div class="refsect1 unknown-seealsp" id="refsect1-function.oci-define-by-name-unknown-seealsp">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>oci_define_by_name</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$statement</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$column_name</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter reference">&$variable</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code></span>
  ] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>oci_define_by_name()</strong></span> 绑定 PHP 到获取的
   SQL 列。 需要注意的是，Oracle 使用大写字母的列名，而用户在
   select 中也可以用小写字母。<span class="function"><strong>oci_define_by_name()</strong></span>
   期望 <code class="parameter">column_name</code> 是大写字母。如果定义一个变量不存在于
   select 语句中，将没有错误被给出。
  </p>
  <p class="para">
   如果需要定义一个抽象数据类型（LOB/ROWID/BFILE），必须先用
   <span class="function"><a href="oci_new_descriptor.html" class="function">oci_new_descriptor()</a></span> 分配空间。参见
   <span class="function"><a href="oci_bind_by_name.html" class="function">oci_bind_by_name()</a></span> 函数。
  </p>
   <div class="example" id="example-2405">
    <p><strong>Example #1 <span class="function"><strong>oci_define_by_name()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;oci_define_by_name&nbsp;example&nbsp;-&nbsp;thies&nbsp;at&nbsp;thieso&nbsp;dot&nbsp;net&nbsp;(980219)&nbsp;*/<br /><br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"scott"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"tiger"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;empno,&nbsp;ename&nbsp;FROM&nbsp;emp"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;the&nbsp;define&nbsp;MUST&nbsp;be&nbsp;done&nbsp;BEFORE&nbsp;oci_execute!&nbsp;*/<br /><br /></span><span style="color: #0000BB">oci_define_by_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EMPNO"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$empno</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_define_by_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ENAME"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ename</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br />while&nbsp;(</span><span style="color: #0000BB">oci_fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"empno:"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$empno&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"ename:"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$ename&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">oci_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

  </div>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    在 PHP 5.0.0 之前的版本必须使用 <span class="function"><a href="ocidefinebyname.html" class="function">ocidefinebyname()</a></span>
    替代本函数。该函数名仍然可用，为向下兼容作为
    <span class="function"><strong>oci_define_by_name()</strong></span> 的别名。不过其已被废弃，不推荐使用。
   </p>
  </p></blockquote>
 </div>

</div></div></div></body></html>